package com.ug.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;

/**
 * @Author LY
 * @create 2024/7/16 17:07
 * @Description mybatis-plus配置对象自动填充
 */
@Configuration
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 自动填充createTime
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", LocalDateTime::now, LocalDateTime.class);
    }

    /**
     * 自动填充updateTime
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::now, LocalDateTime.class);
    }
}
